package com.example.yaja.yaja.service;

import com.example.yaja.yaja.dao.NewsMapper;
import com.example.yaja.yaja.entity.News;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Zero on 2017/12/4.
 */
@Service("newsService")
public class NewsServiceImpl implements NewsService {

    @Autowired
    NewsMapper newsMapper;


    @Override
    public List<News> findNewsByState(Integer state, Integer number) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("state", state);
        params.put("number", number);
        return newsMapper.selectNewsByState(params);
    }

    @Override
    public int updateNews(News news) {
        return newsMapper.updateByPrimaryKeySelective(news);
    }

    @Override
    public News findNewsById(Integer newsId) {
        return newsMapper.selectByPrimaryKey(newsId);
    }

    @Override
    public int addNews(News news) {
        newsMapper.insertSelective(news);
        Integer newsId=news.getNewsId();
        return newsId;
    }
}
